﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using fideeraSoft.Utils;
using fideeraSoft.Paneles;
using fideeraSoft.Handlers;
using fideeraSoft.Forms;
using fideeraSoft.Entities;

namespace fideeraSoft
{
    public partial class FideeraForm : Form
    {
      
        // Use DllImport to import the Win32 MessageBox function.
      
        //public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
        private Handler handler;

        public FideeraForm()
        { 
        
        }
        public FideeraForm(Handler handler)
        {
            

            InitializeComponent();

            this.handler = handler;

            
            this.WindowState = FormWindowState.Maximized;
            
            //this.Location = new Point(0, 0);
           // this.MaximizeBox = false;
           // this.MinimizeBox = false;
            

                
            //this.ControlBox = false;
            this.handler.FormFrame = this;

           
            CLogger.Init();

            CLogger.Append("[FideeraForm] Comenzando form", CLogger.INFO);      //DEBUG


            ///RESTRICCIONES POR USUARIO
            switch(UsuarioLoggin.jerarquia)
            {
                case "superusuario":
                    //menuAdministracion.Visible = false;
                    menuCrearLoginUser.Visible = false;
                    menuAdministracionGeneral.Visible = false;

                    menuEliminarProduccion.Visible = false;
                    menuEliminarEnvasado.Visible = false;

                    break;

                case "operador":
                    menuAdministracion.Visible = false;
                    menuUsuario.Visible = false;
                    menuModificarRemitoEntrada.Visible = false;
                    menuEliminarProduccion.Visible = false;
                    menuEliminarEnvasado.Visible = false;
                                        
                    //menuAltaUsuario.Visible = false;
                    //menuModificarUsuario.Visible = false;
                    //menuBajaUsuario.Visible = false;

                    break;

                case "administrador":
                    menuAdministracion.Visible = false;
                    menuEliminarProduccion.Visible = false;
                    menuEliminarEnvasado.Visible = false;

                    
                    break;

                default:
                    break;
            }
            
           // MessageBox.Show("TAMAÑO: " + this.handler.FormFrame.Size.Height + " - " + this.handler.FormFrame.Size.Width, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            
            this.WindowState = FormWindowState.Maximized;
           
           
            this.Controls.Add(MetodosGenerales.crearPanelConImagen(this.Size));

            this.Show();
            //new FormLogeoUsuario(this);

            
            //this.Dock = DockStyle.Fill;
        }



        #region Metodos FORM
        private void Form1_Load(object sender, EventArgs e)
        {
            
         
        
        }

        private void FideeraForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //for (int index =0; index<= Application.OpenForms.Count;index++)
            //{
            //    if (Application.OpenForms[index].Name == "FideeraForm")
            //    {
            //        Application.OpenForms[index].Close();
            //    }
            //}
            
        }

        private void FideeraForm_LocationChanged(object sender, EventArgs e)
        {
           
            //this.Location = new Point(0, 0);
        }
        protected override void WndProc(ref Message m)
        {
            const int WM_NCLBUTTONDOWN = 161;
            const int WM_SYSCOMMAND = 274;
            const int HTCAPTION = 2;
            const int SC_MOVE = 61456;
            const int WM_NCLBUTTONDBLCLK = 163;

            if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))
                return;
            if ((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))
                return;
            if(m.Msg == WM_NCLBUTTONDBLCLK)
                return;

            base.WndProc(ref m);
        }
        private void FideeraForm_DoubleClick(object sender, EventArgs e)
        {

        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Maximized)
            {
                WindowState = FormWindowState.Normal;
            }
        }

        #endregion
        #region methods

        private void crearLoginUserToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //this.Controls.Add(new AdministracionPanel());

        }

        private void altaToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // MessageBox.Show("ALTA");      //DEBUG
            //this.Controls.Add(new ProveedorPanelAlta(this));
            switchPanel(new ProveedorPanelAlta(handler));
        }

        

        private void generalToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // this.Controls.Add(new AdministracionPanel(this));
            switchPanel(new AdministracionPanel(handler));
        }

        public void switchPanel(Panel panel)
        {
            int x = 0;
            // this.Controls.Clear();

            if (this.Controls.Count > 0)
            {
                while (x < this.Controls.Count)
                {
                    if (this.Controls[x] is Panel)
                    {
                        this.Controls.Remove(this.Controls[x]);
                    }
                    x++;
                }
            }
            this.Controls.Add(panel);
        }

        #endregion


        #region MENU PROVEEDOR
        private void modificarProveedorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProveedorPanelModificar(handler));
        }

        private void bajaProveedorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProveedorPanelBaja(handler));
        }

        #endregion

        #region MENU USUARIO

        private void altaUsuarioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new UsuarioPanelAlta(handler));

        }

        private void modificarUsuarioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new UsuarioPanelModificar(handler));
        }

        private void bajaUsuarioToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new UsuarioPanelBaja(handler));
        }

        #endregion

        #region MENU PRODUCTO
        private void altaProductoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProductoPanelAlta(handler));
        }

        private void modificarProductoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProductoPanelModificacion(handler));

        }

        private void bajaProductoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProductoPanelBaja(handler));
        }

        #endregion  

        #region MENU MATERIA PRIMA
        private void altaMateriaPrimaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new MateriaPrimaPanelAlta(handler));
        }

        private void modificarMateriaPrimaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new MateriaPrimaPanelModificar(handler));
        }

        private void bajaMateriaPrimaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new MateriaPrimaPanelBaja(handler));
        }
        #endregion

        #region MENU  REMITO ENTRADA
        private void modificarRemitoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new RemitoPanelModificar(handler));
        }

        private void altaDeRemitoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new RemitoPanelAlta(handler));
        }

        private void bajaDeRemitoDeEntradaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new RemitoPanelBaja(handler));
        }

        #endregion 

        #region MENU SALIR
        private void cerrarSesionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }

        private void salirToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion

        #region MENU PRODUCCIÓN
        private void iniciarProducciónToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProduccionPanelInicio(handler));
        }
              
        private void modificarProducciónToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProduccionPanelFin(handler));
        }

        private void eliminarProducciónToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ProduccionPanelBaja(handler));
        }

        #endregion


        #region MENU ENVASADO
        private void menuIniciarEnvasado_Click(object sender, EventArgs e)
        {
            switchPanel(new EnvasadoPanelInicio(handler));
        }

        private void menuFinalizarEnvasado_Click(object sender, EventArgs e)
        {
            switchPanel(new EnvasadoPanelFin(handler));
        }

        #endregion

        #region MENU SALIDA
        private void remitoDeSalidaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new RemitoSalidaPanel(handler));
        }
        #endregion

        #region MENU CONSULTAS
        private void menuConsultaRemitosSalida_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaRemitosDeSalidaPanel(handler));
        }

        private void menuConsultaStockActual_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaStockActualPanel(handler));
        }

        private void stockActualPorProductoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaStockActualPorMateriaPrimaPanel(handler));
        }
        private void menuConsultaProduccionesIniciadas_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaProduccionesIniciadasPanel(handler));
        }
        
        private void menuConsultaProduccionesFinalizadas_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaProduccionesFinalizadasPanel(handler));
        }

        private void menuConsultaProduccionesEnvasadas_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaProduccionesFinEnvasadasPanel(handler));
        }

        private void menuConsultaStockProductosTerminados_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaPaquetesPorProductoTerminadoPanel(handler));
        }

        private void menuTrazabilidadLotesUtilizados_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaTrazabilidadLotesUtilizadosPanel(handler));
        }

        private void menuTrazabilidadPorCodigoEnvasado_Click(object sender, EventArgs e)
        {
            switchPanel(new ConsultaTrazabilidadPorCodigoEnvasadoPanel(handler));
        }

        #endregion

        #region MENU AYUDA
        private void menuAyudaComoFunciona_Click(object sender, EventArgs e)
        {
            ///TODO
        }

        private void menuAyudaComentarios_Click(object sender, EventArgs e)
        {
            ///TODO
        }
        private void menuAyudaAcercaDe_Click(object sender, EventArgs e)
        {
            ///TODO
        }
        #endregion

        #region MENU ADMINISTRACION
        private void menuEliminiarDatosEnDB_Click(object sender, EventArgs e)
        {
            ///TODO
            ///
            switchPanel(new EliminarTablasBaseDeDatos(handler));
        }
        #endregion

      

        













    }
}
